package com.bjpowernode.controller;

import com.bjpowernode.entity.TClue;
import com.bjpowernode.common.result.Result;
import com.bjpowernode.service.ClueService;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequiredArgsConstructor
@Slf4j
public class ClueController {

    private final ClueService clueService;


    @GetMapping("/api/clue")
    public Result getClueByPage(@RequestParam("current") Integer current) {
        PageInfo<TClue> pageInfo = clueService.getClueByPage(current);
        return Result.OK(pageInfo);
    }

    @RequestMapping("/api/importExcel")
    public Result importExcel(MultipartFile excelFile) throws IOException {
        clueService.importExcel(excelFile.getInputStream());
        return Result.OK();

    }

    @GetMapping("/api/clue/{id}")
    public Result getClueById(@PathVariable("id") Integer id) {
        TClue clue = clueService.getClueById(id);
        return Result.OK(clue);
    }
}
